<?php
namespace App\Base;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Cache;
use App\Base\Base;
use Config;

class WeChatBase extends Controller {
	/**
	 * [getUserInfo 小程序获取用户详情]
	 * @Author:  刘家腾
	 * @DateTime 2019-06-03
	 * @param    [type]     $postData [description]
	 * @return   [type]               [description]
	 */
	public static function getUserInfo($postData){

		$wheData['status'] = 1;
		$wheData['open_id'] = $postData['open_id'];

		return DB::table('user') ->where($wheData) ->get()->toArray();
	}
	/**
	 * [getAccessToken 获取access_token]
	 * @Author:  刘家腾
	 * @DateTime 2019-06-19
	 * @return   [type]     [description]
	 */
	public static function getAccessToken(){
		$access_token = Cache::get('access_token');
        if(empty($access_token)){
            $config = Config::get('wechat.default');
            $tokenurl = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$config['app_id'].'&secret='.$config['app_secret'];
            $getData = Base::httpGet($tokenurl);
            Cache::put('access_token',$getData['access_token'],7000);
            $access_token = $getData['access_token'];
        }
        return $access_token;
	}
	
}